/*
 * To change this template, choose Tools | Templates and open the template in
 * the editor.
 */
package SteamEngineFX.Layouts;

import SteamEngineDB.ScheduleCar;
import SteamEngineDB.ScheduleRun;
import SteamEngineFX.SteamEngineFX;
import SteamEngineFX.util.RunTime;
import java.util.Iterator;
import javafx.geometry.Pos;
import javafx.scene.control.ContentDisplay;
import javafx.scene.control.Hyperlink;
import javafx.scene.control.Label;
import javafx.scene.control.ProgressBar;
import javafx.scene.effect.DropShadow;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;
import javafx.scene.paint.CycleMethod;
import javafx.scene.paint.RadialGradient;
import javafx.scene.shape.Rectangle;

/**
 *
 * @author Jeff Bendixsen <jeff@westcoastcode.com>
 */
public class RunPane extends Region{
    
    public final static String RunPaneStyle = "";
    
    private ScheduleRun run = null;
    
    private VBox outerVBox = null;
    private VBox equipBox = null;
    
    private String runName = "";
    //private Double runUsage = 0.0;
    
    private ImageView bullet = null;
    
    private static final Image DateTime24 = new Image(SteamEngineFX.class.getResourceAsStream("/steamenginefx/resources/date_time24.png"));
    private static final Image BulletBall24 = new Image(SteamEngineFX.class.getResourceAsStream("/steamenginefx/resources/bullet_ball_grey24.png"));
    private static final Image BulletBall16 = new Image(SteamEngineFX.class.getResourceAsStream("/steamenginefx/resources/bullet_ball_grey16.png"));
    
    public RunPane(ScheduleRun scheduleRun){

        if (scheduleRun == null){
            System.out.println("RunPane was passed a null ScheduleRun");
        }
        
        run = scheduleRun;
        runName = new RunTime(run.getRunTime()).toString();
        //runUsage = usage;
        
        outerVBox = new VBox();

        // Add flashy background
        RadialGradient rg = new RadialGradient(USE_PREF_SIZE, USE_PREF_SIZE, USE_PREF_SIZE, USE_PREF_SIZE, USE_PREF_SIZE, true, CycleMethod.REPEAT, null);
        Rectangle r = new Rectangle(getWidth(), getHeight(), rg);
        getChildren().add(r);        

        // Hyperlink for selecting the run
        Hyperlink selectRun = new Hyperlink(runName);
        selectRun.setGraphic(new ImageView(DateTime24));
        selectRun.setContentDisplay(ContentDisplay.LEFT);
        selectRun.getStyleClass().add("labelRun");
        selectRun.setEffect(new DropShadow());
        
        outerVBox.getChildren().add(selectRun);
        
        equipBox = new VBox();
        
        for(Iterator<ScheduleCar> j = run.getScheduleCarCollection().iterator(); j.hasNext();){

            ScheduleCar e = j.next();

            Label Car = new Label(e.getCarId().getName());
            Car.getStyleClass().add("labelRunCar");
            Car.setMaxWidth(USE_PREF_SIZE);

            ProgressBar pbUsage = new ProgressBar();
            pbUsage.setProgress(0.5);

            VBox vb = new VBox();
            vb.getChildren().addAll(Car, pbUsage);

            ImageView bullet = new ImageView(BulletBall16);
            HBox hb = new HBox();
            hb.getChildren().addAll(bullet, vb);

            equipBox.getChildren().add(hb);
        }
        outerVBox.getChildren().add(equipBox);
        
        getChildren().add(outerVBox);
               
    }
    
    @Override
    public String toString(){
        return "RunPane: " + new RunTime(run.getRunTime()).toString();
    }
    
    public void setUsage(ScheduleCar Car, Double newUsage){
        
        
        //runUsage = newUsage;
        //pbUsage.setProgress(runUsage);
    }
    
    
}
